﻿@{
    ViewBag.Title = "OlsenOlsen";
}
<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/cardstyle.css")" />
<script type="text/javascript" src="@Url.Content("~/Scripts/cards.js")"></script>
<script type="text/javascript">

    var deck, discards, player01, player02, numPlayers = 2;
    window.onload = init;
    function init() {
        deck = new Stack();
        discards = new Stack();
        player01 = new Stack();
        player02 = new Stack();

        deck.makeDeck(1);
        deck.shuffle(21);
    }

    function turnOverDeck() {
        var j = discards.cardCount();
        for (i = 0; i < j; i++) {
            deck.addCard(discards.cards[i]);
        }
    }
</script>

<h2>Olsen Olsen</h2>
<div id="cardArea">
    <h2>Spil á hönd</h2>
    <div id="deck01"></div>
    <div id="deck02"></div>
    <div id="deck03"></div>
    <div id="deck04"></div>
</div>
<div id="playTable">
    <div class="card" id="deckurinn">
        <div id="cardDock"></div>
    </div>
    <div class="deckOfCards"></div>
    <script>
        $("#cardDock").click(function () {
            alert("klikkaður");
            player01.addCard(discards.cards[j]);
            $("#cardDock .card").appendTo("#deck01");
        });
        var m = 0;
        $(".deckOfCards").click(function () {
            if (deck.cardCount() > 0) {
                discards.addCard(deck.deal());
                $(discards.cards[m].createNode()).appendTo("#cardDock");
                m++;
            }
            else {
                turnOverDeck();
                $("#cardDock .card").remove();
            }
        });
    </script>
    <div id="seat01">    </div>
    <div id="seat02">    </div>
    <div id="seat03">    </div>
    <div id="seat04">    </div>
</div>
<button id="deal">Byrjum leikinn</button>
<div id="ChatIt">
    @Html.Partial("_ChatWindow")
</div>
<script>
    $("#deal").click(function () {
        var node, leftIncr = 5;

        for (i = 0; i < 5; i++) {
            player01.addCard(deck.deal());
            player02.addCard(deck.deal());
            node = player01.cards[i].createNode();
            node.style.left = leftIncr + "px";
            $(node).appendTo("#deck01");
            node = player02.cards[i].createNode();
            node.style.left = leftIncr + "px";
            $(node).appendTo("#deck02");
            leftIncr = leftIncr + 20;
        }
    });
</script>